#include "apue.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include "error.c"

#ifdef OPEN_MAX
static long openmax = OPEN_MAX;
#else
static long openmax = 0;
#endif

#define OPEN_MAX_GUESS 256

long open_max(void){
    if(openmax == 0)
        errno = 0;

    if((openmax = sysconf(_SC_OPEN_MAX)) < 0){
        if(errno == 0)
            openmax = OPEN_MAX_GUESS;
        else{
            err_sys("sysconf error for _SC_OPEN_MAX");
        }
    }

    return openmax;
}

int main(int argc, char const *argv[])
{
    printf("OPEN_MAX: %ld\n", open_max());
    struct rlimit rl; 
    if(getrlimit(RLIMIT_NOFILE, &rl) != 0){
        err_sys("getrlimit error.");
    }else{
        printf("NOFILE RESOURCE LIMIT NUMBER: cur, %llu\nmax, %llu\n", rl.rlim_cur, rl.rlim_max);
    }

    off_t

    return 0;
}
